<?php
if ( IPB_THIS_SCRIPT != 'admin' )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded 'init.php'.";
	exit();
}

define('LIMIT_TO_ONLY_ROOY',1);

class ad_converter
{
	var $ipsclass;
	var $converters = array();
	
	function auto_run()
	{
		if (LIMIT_TO_ONLY_ROOY && $this->ipsclass->member['mgroup'] != $this->ipsclass->vars['admin_group'])
		{
			$this->ipsclass->admin->error("Sorry, this page is only for root admin only.");
		}
		
		if(file_exists(ROOT_PATH."sources/null") || file_exists(ROOT_PATH."dgt_released.nfo") || file_exists(ROOT_PATH."sources/file_id.diz"))
		{
			$this->ipsclass->admin->error("The author does not like you to use his modification on nulled boards");
		}
		
		$files = $this->ipsclass->market_class->get_file_list(ROOT_PATH."sources/market/converter",0);
		foreach($files as $file)
		{
			if(substr($file,-4) != '.php')
			{
				continue;
			}
			
			$class_name = $this->ipsclass->market_class->get_class_name($file);
			$class = $this->ipsclass->load_class(ROOT_PATH."/sources/market/converter/".$file,$class_name.'_converter');
			if($class->has_mod_installed())
			{
				$this->converters[$class_name] = $class;
			}
		}
		
		$code_redirect = array(
								'' => 'home_page',
								'convert' => 'do_conversion',
							);
		if(!$code_redirect[$this->ipsclass->input['do']])
		{
			$this->ipsclass->input['do'] = '';
		}
		$run = $code_redirect[$this->ipsclass->input['do']];
		$this->$run();		
	}
	
	function home_page()
	{
		if (LIMIT_TO_ONLY_ROOY && $this->ipsclass->member['mgroup'] != $this->ipsclass->vars['admin_group'])
		{
			$this->ipsclass->admin->error("Sorry, this page is only for root admin only.");
		}

		$failed = $this->ipsclass->market_admin->check_conditions();
		
		if(count($failed) != 0)
		{
			$this->ipsclass->admin->error("You must have to pass all conditions before converting");
		}
		
		$this->ipsclass->admin->page_title  = "Welcome to converting to ibMarket from another mod";
		$this->ipsclass->admin->page_detail = "Welcome to converting to ibMarket from another mod. Remember to backup your database before applying any of these conversions.";
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=database', 'Database Handler'   );
		$this->ipsclass->admin->nav[] 		= array( $this->ipsclass->form_code.'&amp;code=convert' , 'ibMarket Converter' );
		
		foreach($this->converters as $converter)
		{
			foreach($converter->home_page() as $html)
			{
				$this->ipsclass->html .= $html;
			}
		}
		
		$this->ipsclass->admin->output();
	}
	
	function do_conversion()
	{
		if(!is_object($this->converters[$this->ipsclass->input['other']]))
		{
			$this->ipsclass->admin->redirect($this->ipsclass->form_code_js."&code=convert","...");
		}
		
		$this->converters[$this->ipsclass->input['other']]->convert();
	}
}
?>